Frisk = CreateSprite("Overworld/Characters/Frisk/FriskRSN1","Top")
Frisk.SetPivot(0.5, 0)
FrameFrisk = 1
FriskDirection = "R"
FriskTimer = 0
FriskAutomatico = false
FriskDireccionAuto = "R"
FriskAlowMovementUD = true
FriskAlowMovementLR = true
FriskAnimation = true
FriskAnimationAuto = false
FriskVel = 3
FriskFrameVel = 10
TipoFrisk = "SN"

function FriskUpdate()
	Frisk.Set("Overworld/Characters/Frisk/Frisk" .. FriskDirection .. TipoFrisk .. FrameFrisk)
	if ( Input.Up > 0 and Input.Down == 0 and Input.Left == 0 and Input.Right == 0 and FriskAnimation == true ) or ( FriskDireccionAuto == "U" and ( FriskAutomatico == true or FriskAnimationAuto == true )) then
		FriskDirection = "U"
	elseif ( Input.Up == 0 and Input.Down > 0 and Input.Left == 0 and Input.Right == 0 and FriskAnimation == true ) or ( FriskDireccionAuto == "D" and ( FriskAutomatico == true or FriskAnimationAuto == true )) then
		FriskDirection = "D"
	elseif ( Input.Up == 0 and Input.Down == 0 and Input.Left > 0 and Input.Right == 0 and FriskAnimation == true ) or ( FriskDireccionAuto == "L" and ( FriskAutomatico == true or FriskAnimationAuto == true )) then
		FriskDirection = "L"
	elseif ( Input.Up == 0 and Input.Down == 0 and Input.Left == 0 and Input.Right > 0 and FriskAnimation == true ) or ( FriskDireccionAuto == "R" and ( FriskAutomatico == true or FriskAnimationAuto == true )) then
		FriskDirection = "R"
	end
	if Input.Up > 0 and Input.Down == 0 and FriskDirection == "D" and ( Input.Left > 0 or Input.Right < 0 ) and FriskAnimation == true then
		FriskDirection = "U"
	elseif Input.Up == 0 and Input.Down > 0 and FriskDirection == "U" and ( Input.Left > 0 or Input.Right > 0 ) and FriskAnimation == true then
		FriskDirection = "D"
	elseif ( Input.Up > 0 or Input.Down > 0 ) and Input.Left > 0 and Input.Right == 0 and FriskDirection == "R" and FriskAnimation == true then
		FriskDirection = "L"
	elseif ( Input.Up > 0 or Input.Down > 0 ) and Input.Left == 0 and Input.Right > 0 and FriskDirection == "L" and FriskAnimation == true then
		FriskDirection = "R"
	end
	if ( Input.Up > 0 and FriskAlowMovementUD == true ) or ( FriskAutomatico == true and FriskDireccionAuto == "U" ) then
		Frisk.y = Frisk.y + FriskVel
	elseif ( Input.Down > 0 and FriskAlowMovementUD == true ) or ( FriskAutomatico == true and FriskDireccionAuto == "D" ) then
		Frisk.y = Frisk.y - FriskVel
	end
	if ( Input.Left > 0 and Input.Right == 0 and FriskAlowMovementLR == true ) or ( FriskAutomatico == true and FriskDireccionAuto == "L" ) then
		Frisk.x = Frisk.x - FriskVel
	elseif (Input.Left == 0 and Input.Right > 0 and FriskAlowMovementLR == true ) or ( FriskAutomatico == true and FriskDireccionAuto == "R" ) then
		Frisk.x = Frisk.x + FriskVel
	end
	if (( Input.Up > 0 or Input.Down > 0 or Input.Left > 0 or Input.Right > 0) and FriskAnimation == true ) or FriskAutomatico == true or FriskAnimationAuto == true then
		FriskTimer = FriskTimer + 1
	elseif ( Input.Up == 0 and Input.Down == 0 and Input.Left == 0 and Input.Right == 0 and FriskAnimation == true ) or FriskAutomatico == false then
		FriskTimer = 1
		FrameFrisk = 1
	end
	if FriskTimer == 2 then
		FrameFrisk = FrameFrisk + 1
	elseif FriskTimer%FriskFrameVel == 0 then
		FrameFrisk = FrameFrisk + 1
		if FrameFrisk == 5 then
			FrameFrisk = 1
		end
	end
end

function RespawnFrisk(layer)
	local XFrisk = Frisk.x
	local YFrisk = Frisk.y
	Frisk.Remove()
	Frisk = CreateSprite("Overworld/Characters/Frisk/Frisk" .. FriskDirection .. TipoFrisk .. FrameFrisk,layer)
	Frisk.MoveTo(XFrisk, YFrisk)
end

function AlowFriskMovement(alow, animation)
	FriskAlowMovementLR = alow
	FriskAlowMovementUD = alow
	FriskAnimation = animation
	FriskAutomatico = false
	FriskAnimationAuto = false
end

function AnimationAutoFrisk(direction)
	FriskAutomatico = false
	FriskAnimationAuto = true
	FriskAlowMovementLR = false
	FriskAlowMovementUD = false
	FriskAnimation = false
	if direction == "Up" or direction == "Arriba" then
		FriskDireccionAuto = "U"
	elseif direction == "Down" or direction == "Abajo" then
		FriskDireccionAuto = "D"
	elseif direction == "Left" or direction == "Izquierda" then
		FriskDireccionAuto = "L"
	elseif direction == "Right" or direction == "Derecha" then
		FriskDireccionAuto = "R"
	end
end

function FriskAuto(direction)
	FriskAutomatico = true
	FriskAnimationAuto = false
	FriskAlowMovementUD = false
	FriskAlowMovementLR = false
	FriskAnimation = false
	if direction == "Up" or direction == "Arriba" then
		FriskDireccionAuto = "U"
	elseif direction == "Down" or direction == "Abajo" then
		FriskDireccionAuto = "D"
	elseif direction == "Left" or direction == "Izquierda" then
		FriskDireccionAuto = "L"
	elseif direction == "Right" or direction == "Derecha" then
		FriskDireccionAuto = "R"
	end
end